.class public Lcom/android/inputmethod/latin/BinaryDictionary;
.super Lcom/android/inputmethod/latin/Dictionary;
.source "BinaryDictionary.java"


# static fields
.field private static final ENABLE_MISSED_CHARACTERS:Z = true

.field private static final MAX_ALTERNATIVES:I = 0x10

.field private static final MAX_WORDS:I = 0x10

.field public static final MAX_WORD_LENGTH:I = 0x30

.field private static final TYPED_LETTER_MULTIPLIER:I = 0x2


# instance fields
.field private mFrequencies:[I

.field private mInputCodes:[I

.field private mNativeDict:I

.field private mOutputChars:[C


# direct methods
.method static constructor <clinit>()V
    .locals 3

    .prologue
    .line 44
    :try_start_0
    const-string v1, "jni_latinime"

    invoke-static {v1}, Ljava/lang/System;->loadLibrary(Ljava/lang/String;)V
    :try_end_0
    .catch Ljava/lang/UnsatisfiedLinkError; {:try_start_0 .. :try_end_0} :catch_0

    .line 48
    :goto_0
    return-void

    .line 45
    :catch_0
    move-exception v1

    move-object v0, v1

    .line 46
    .local v0, ule:Ljava/lang/UnsatisfiedLinkError;
    const-string v1, "BinaryDictionary"

    const-string v2, "Could not load native library jni_latinime"

    invoke-static {v1, v2}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

    goto :goto_0
.end method

.method public constructor <init>(Landroid/content/Context;I)V
    .locals 2
    .parameter "context"
    .parameter "resId"

    .prologue
    const/16 v1, 0x300

    .line 55
    invoke-direct {p0}, Lcom/android/inputmethod/latin/Dictionary;-><init>()V

    .line 38
    new-array v0, v1, [I

    iput-object v0, p0, Lcom/android/inputmethod/latin/BinaryDictionary;->mInputCodes:[I

    .line 39
    new-array v0, v1, [C

    iput-object v0, p0, Lcom/android/inputmethod/latin/BinaryDictionary;->mOutputChars:[C

    .line 40
    const/16 v0, 0x10

    new-array v0, v0, [I

    iput-object v0, p0, Lcom/android/inputmethod/latin/BinaryDictionary;->mFrequencies:[I

    .line 56
    if-eqz p2, :cond_0

    .line 57
    invoke-direct {p0, p1, p2}, Lcom/android/inputmethod/latin/BinaryDictionary;->loadDictionary(Landroid/content/Context;I)V

    .line 59
    :cond_0
    return-void
.end method

.method private native closeNative(I)V
.end method

.method private native getSuggestionsNative(I[II[C[IIIII)I
.end method

.method private native isValidWordNative(I[CI)Z
.end method

.method private final loadDictionary(Landroid/content/Context;I)V
    .locals 4
    .parameter "context"
    .parameter "resId"

    .prologue
    const/4 v3, 0x2

    .line 70
    invoke-virtual {p1}, Landroid/content/Context;->getResources()Landroid/content/res/Resources;

    move-result-object v2

    invoke-virtual {v2}, Landroid/content/res/Resources;->getAssets()Landroid/content/res/AssetManager;

    move-result-object v0

    .line 71
    .local v0, am:Landroid/content/res/AssetManager;
    invoke-virtual {p1}, Landroid/content/Context;->getResources()Landroid/content/res/Resources;

    move-result-object v2

    invoke-virtual {v2, p2}, Landroid/content/res/Resources;->getString(I)Ljava/lang/String;

    move-result-object v1

    .line 72
    .local v1, assetName:Ljava/lang/String;
    invoke-direct {p0, v0, v1, v3, v3}, Lcom/android/inputmethod/latin/BinaryDictionary;->openNative(Landroid/content/res/AssetManager;Ljava/lang/String;II)I

    move-result v2

    iput v2, p0, Lcom/android/inputmethod/latin/BinaryDictionary;->mNativeDict:I

    .line 73
    return-void
.end method

.method private native openNative(Landroid/content/res/AssetManager;Ljava/lang/String;II)I
.end method


# virtual methods
.method public declared-synchronized close()V
    .locals 1

    .prologue
    .line 129
    monitor-enter p0

    :try_start_0
    iget v0, p0, Lcom/android/inputmethod/latin/BinaryDictionary;->mNativeDict:I

    if-eqz v0, :cond_0

    .line 130
    iget v0, p0, Lcom/android/inputmethod/latin/BinaryDictionary;->mNativeDict:I

    invoke-direct {p0, v0}, Lcom/android/inputmethod/latin/BinaryDictionary;->closeNative(I)V

    .line 131
    const/4 v0, 0x0

    iput v0, p0, Lcom/android/inputmethod/latin/BinaryDictionary;->mNativeDict:I
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    .line 133
    :cond_0
    monitor-exit p0

    return-void

    .line 129
    :catchall_0
    move-exception v0

    monitor-exit p0

    throw v0
.end method

.method protected finalize()V
    .locals 0
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/lang/Throwable;
        }
    .end annotation

    .prologue
    .line 137
    invoke-virtual {p0}, Lcom/android/inputmethod/latin/BinaryDictionary;->close()V

    .line 138
    invoke-super {p0}, Ljava/lang/Object;->finalize()V

    .line 139
    return-void
.end method

.method public getWords(Lcom/android/inputmethod/latin/WordComposer;Lcom/android/inputmethod/latin/Dictionary$WordCallback;)V
    .locals 22
    .parameter "codes"
    .parameter "callback"

    .prologue
    .line 77
    invoke-virtual/range {p1 .. p1}, Lcom/android/inputmethod/latin/WordComposer;->size()I

    move-result v8

    .line 79
    .local v8, codesSize:I
    const/16 v5, 0x2f

    if-le v8, v5, :cond_1

    .line 119
    :cond_0
    return-void

    .line 81
    :cond_1
    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/android/inputmethod/latin/BinaryDictionary;->mInputCodes:[I

    move-object v5, v0

    const/4 v6, -0x1

    invoke-static {v5, v6}, Ljava/util/Arrays;->fill([II)V

    .line 82
    const/16 v17, 0x0

    .local v17, i:I
    :goto_0
    move/from16 v0, v17

    move v1, v8

    if-ge v0, v1, :cond_2

    .line 83
    move-object/from16 v0, p1

    move/from16 v1, v17

    invoke-virtual {v0, v1}, Lcom/android/inputmethod/latin/WordComposer;->getCodesAt(I)[I

    move-result-object v15

    .line 84
    .local v15, alternatives:[I
    const/4 v5, 0x0

    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/android/inputmethod/latin/BinaryDictionary;->mInputCodes:[I

    move-object v6, v0

    mul-int/lit8 v7, v17, 0x10

    array-length v9, v15

    const/16 v10, 0x10

    invoke-static {v9, v10}, Ljava/lang/Math;->min(II)I

    move-result v9

    invoke-static {v15, v5, v6, v7, v9}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V

    .line 82
    add-int/lit8 v17, v17, 0x1

    goto :goto_0

    .line 87
    .end local v15           #alternatives:[I
    :cond_2
    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/android/inputmethod/latin/BinaryDictionary;->mOutputChars:[C

    move-object v5, v0

    const/4 v6, 0x0

    invoke-static {v5, v6}, Ljava/util/Arrays;->fill([CC)V

    .line 88
    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/android/inputmethod/latin/BinaryDictionary;->mFrequencies:[I

    move-object v5, v0

    const/4 v6, 0x0

    invoke-static {v5, v6}, Ljava/util/Arrays;->fill([II)V

    .line 90
    move-object/from16 v0, p0

    iget v0, v0, Lcom/android/inputmethod/latin/BinaryDictionary;->mNativeDict:I

    move v6, v0

    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/android/inputmethod/latin/BinaryDictionary;->mInputCodes:[I

    move-object v7, v0

    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/android/inputmethod/latin/BinaryDictionary;->mOutputChars:[C

    move-object v9, v0

    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/android/inputmethod/latin/BinaryDictionary;->mFrequencies:[I

    move-object v10, v0

    const/16 v11, 0x30

    const/16 v12, 0x10

    const/16 v13, 0x10

    const/4 v14, -0x1

    move-object/from16 v5, p0

    invoke-direct/range {v5 .. v14}, Lcom/android/inputmethod/latin/BinaryDictionary;->getSuggestionsNative(I[II[C[IIIII)I

    move-result v16

    .line 98
    .local v16, count:I
    const/4 v5, 0x5

    move/from16 v0, v16

    move v1, v5

    if-ge v0, v1, :cond_3

    .line 99
    const/4 v14, 0x0

    .local v14, skip:I
    :goto_1
    if-ge v14, v8, :cond_3

    .line 100
    move-object/from16 v0, p0

    iget v0, v0, Lcom/android/inputmethod/latin/BinaryDictionary;->mNativeDict:I

    move v6, v0

    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/android/inputmethod/latin/BinaryDictionary;->mInputCodes:[I

    move-object v7, v0

    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/android/inputmethod/latin/BinaryDictionary;->mOutputChars:[C

    move-object v9, v0

    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/android/inputmethod/latin/BinaryDictionary;->mFrequencies:[I

    move-object v10, v0

    const/16 v11, 0x30

    const/16 v12, 0x10

    const/16 v13, 0x10

    move-object/from16 v5, p0

    invoke-direct/range {v5 .. v14}, Lcom/android/inputmethod/latin/BinaryDictionary;->getSuggestionsNative(I[II[C[IIIII)I

    move-result v21

    .line 103
    .local v21, tempCount:I
    move/from16 v0, v16

    move/from16 v1, v21

    invoke-static {v0, v1}, Ljava/lang/Math;->max(II)I

    move-result v16

    .line 104
    if-lez v21, :cond_4

    .line 108
    .end local v14           #skip:I
    .end local v21           #tempCount:I
    :cond_3
    const/16 v18, 0x0

    .local v18, j:I
    :goto_2
    move/from16 v0, v18

    move/from16 v1, v16

    if-ge v0, v1, :cond_0

    .line 109
    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/android/inputmethod/latin/BinaryDictionary;->mFrequencies:[I

    move-object v5, v0

    aget v5, v5, v18

    const/4 v6, 0x1

    if-lt v5, v6, :cond_0

    .line 110
    mul-int/lit8 v20, v18, 0x30

    .line 111
    .local v20, start:I
    const/16 v19, 0x0

    .line 112
    .local v19, len:I
    :goto_3
    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/android/inputmethod/latin/BinaryDictionary;->mOutputChars:[C

    move-object v5, v0

    add-int v6, v20, v19

    aget-char v5, v5, v6

    if-eqz v5, :cond_5

    .line 113
    add-int/lit8 v19, v19, 0x1

    goto :goto_3

    .line 99
    .end local v18           #j:I
    .end local v19           #len:I
    .end local v20           #start:I
    .restart local v14       #skip:I
    .restart local v21       #tempCount:I
    :cond_4
    add-int/lit8 v14, v14, 0x1

    goto :goto_1

    .line 115
    .end local v14           #skip:I
    .end local v21           #tempCount:I
    .restart local v18       #j:I
    .restart local v19       #len:I
    .restart local v20       #start:I
    :cond_5
    if-lez v19, :cond_6

    .line 116
    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/android/inputmethod/latin/BinaryDictionary;->mOutputChars:[C

    move-object v5, v0

    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/android/inputmethod/latin/BinaryDictionary;->mFrequencies:[I

    move-object v6, v0

    aget v6, v6, v18

    move-object/from16 v0, p2

    move-object v1, v5

    move/from16 v2, v20

    move/from16 v3, v19

    move v4, v6

    invoke-interface {v0, v1, v2, v3, v4}, Lcom/android/inputmethod/latin/Dictionary$WordCallback;->addWord([CIII)Z

    .line 108
    :cond_6
    add-int/lit8 v18, v18, 0x1

    goto :goto_2
.end method

.method public isValidWord(Ljava/lang/CharSequence;)Z
    .locals 3
    .parameter "word"

    .prologue
    .line 123
    if-nez p1, :cond_0

    const/4 v1, 0x0

    .line 125
    :goto_0
    return v1

    .line 124
    :cond_0
    invoke-virtual {p1}, Ljava/lang/Object;->toString()Ljava/lang/String;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/String;->toCharArray()[C

    move-result-object v0

    .line 125
    .local v0, chars:[C
    iget v1, p0, Lcom/android/inputmethod/latin/BinaryDictionary;->mNativeDict:I

    array-length v2, v0

    invoke-direct {p0, v1, v0, v2}, Lcom/android/inputmethod/latin/BinaryDictionary;->isValidWordNative(I[CI)Z

    move-result v1

    goto :goto_0
.end method
